package com.weixin.paleituo.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.weixin.paleituo.R;
import com.weixin.paleituo.activity.GoodsDetailsActivity;
import com.weixin.paleituo.base.BaseRecycleAdapter;
import com.weixin.paleituo.bean.HomeRecommandBean;
import com.weixin.paleituo.help.RecycleViewHolder;
import com.weixin.paleituo.util.StringUtils;
import com.weixin.paleituo.util.UIUtils;

import java.util.List;

/**
 * Author yichao
 * Time  2018/4/7 11:23
 * Dest  首页推荐商品
 */
public class HomeRecommandAdapter extends BaseRecycleAdapter<HomeRecommandBean>{


    private TextView mTvGoodsName;
    private TextView mTvNoney;
    private ImageView mIvVip;
    private TextView mTvSaleNumber;
    private ImageView mImageView;

    public HomeRecommandAdapter(Context context, List<HomeRecommandBean> datas) {
        super(context, datas, R.layout.layout_home_recommand_goodes);
    }

    @Override
    protected void setData(RecycleViewHolder holder, final HomeRecommandBean homeRecommandBean, int position) {
        mTvGoodsName = holder.getItemView(R.id.tv_goods_name_layout_home_recommand_goods);
        mTvNoney = holder.getItemView(R.id.tv_money_layout_home_recommand_goods);
        mIvVip = holder.getItemView(R.id.iv_vip__layout_home_recommand_goods);
        mTvSaleNumber = holder.getItemView(R.id.tv_salenumber_layout_home_recommand_goods);
        mImageView = holder.getItemView(R.id.iv_icon_layout_home_recommand_goods);


        mTvGoodsName.setText(homeRecommandBean.getName()+"");
        String specialSales = homeRecommandBean.getSpecialSales();
        if (!StringUtils.isEmpty(specialSales)){
            mIvVip.setVisibility(View.VISIBLE);
            mTvNoney.setTextColor(UIUtils.getColor(R.color.c_29CE7E));

            mTvNoney.setText("￥"+UIUtils.getMoney(Double.valueOf(specialSales)));
        }else {

            mIvVip.setVisibility(View.INVISIBLE);
            mTvNoney.setTextColor(UIUtils.getColor(R.color.c_ed5240));
            mTvNoney.setText("￥"+UIUtils.getMoney(Double.valueOf(homeRecommandBean.getPrice())));
        }


        UIUtils.loadImageViewRoud(mContext,homeRecommandBean.getImg(),mImageView,UIUtils.getDimens(R.dimen.dp_2));
        //Glide.with(mContext).load(homeRecommandBean.getImg()).into(mImageView);

        int goodsSalenum = homeRecommandBean.getGoodsSalenum();
        if (goodsSalenum>0){
            mTvSaleNumber.setText("已售"+goodsSalenum);
        }else {
            mTvSaleNumber.setText("");
        }

        holder.mItemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                GoodsDetailsActivity.startActivity(mContext,homeRecommandBean.getId());

            }
        });


    }
}
